package com.xingda.packing.dmss.common;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public class DateTimeUtils {

    /**
     * 时间字符串(yyyy-MM-dd)转成时间
     */
    public static Date toDate(String dateStr) {
        if (Objects.isNull(dateStr)) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String toStr(Date date) {
        if (Objects.isNull(date)) {
            return null;
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
